package com.rpgfw.graphics;

import java.awt.*;

public class PixelGraphics {
    DrawGraphics obj;
    Color cl=new Color(187,187,187);
    public PixelGraphics(DrawGraphics obj){
        this.obj=obj;
    }

    //graphics

    public void drawPoint(int x,int y){
        obj.drawDot(x, y);
    }
    public void drawLine(int x0,int y0,int x1,int y1) {
        int dx=x1-x0,dyssb=y1-y0;//邓燕是傻逼
        if(Math.abs(dx)>Math.abs(dyssb)) {//长大于高
            int unit=dx/Math.abs(dx);
            double step=(double)dyssb/(double)dx;
            for(int x=x0;Math.abs(x-x1)>0;x+=unit) {
                obj.drawDot(x,(int) (y0+step*(x-x0)));
            }
        }else if(Math.abs(dyssb)>=Math.abs(dx)) {
            int unit=dyssb/Math.abs(dyssb);
            double step=(double)dx/(double)dyssb;
            for(int y=y0;Math.abs(y-y1)>0;y+=unit) {
                obj.drawDot((int) (x0+step*(y-y0)),y);
            }
        }
    }
    private void rect(int x,int y,int w,int h,boolean fill){
        for(int i=0;i<=h;i++){
            for(int j=0;j<=w;j++){
                if(j>0&&i>0&&j<(w)&&i<(h)){
                    if(fill) {
                        obj.drawDot(j + x, i + y);
                    }else {
                        continue;
                    }
                }else{
                    //System.out.println("paint");
                    obj.drawDot(j+x,i+y);
                }
            }
        }
    }
    public void drawRect(int x,int y,int width,int height){
        rect(x,y,width,height,false);
    }
    public void fillRect(int x,int y,int width,int height){
        rect(x,y,width,height,true);
    }


    public void oval(int x,int y,int width,int height,boolean fill){

    }
    public void drawOval(int x,int y,int width,int height){
        oval(x,y,width,height,false);
    }
    public void fillOval(int x,int y,int width,int height){
        oval(x,y,width,height,true);
    }
    public void drawPixelImage(int x,int y,PixelImage pi){
        for(int i=0;i<pi.getHeight();i++){
            for(int j=0;j<pi.getWidth();j++){
                if(pi.bitMap[i][j]=='T'||pi.bitMap[i][j]=='N'){
                    continue;
                }
                this.setColor(pi.getColor(pi.bitMap[i][j]));
                this.obj.drawDot(x+j,y+i);
            }
        }
    }

    //getter&setter

    public void setColor(Color cl){
        this.cl=new Color(cl.getRGB());
        this.obj.changeColor(cl);
    }
    public Color getColor(){
        return new Color(cl.getRGB());
    }
}
